package com.business.dynamic.remote.fallback;

import com.alibaba.fastjson.JSONObject;
import com.business.common.dto.R;
import com.business.common.enums.ErrorEnum;
import com.business.dynamic.remote.UserRemote;
import com.business.user.entity.UserDetailsDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Component
public class UserFallback implements UserRemote {

    private final Logger logger = LoggerFactory.getLogger(UserFallback.class);

    @Override
    public R<UserDetailsDto> queryName(JSONObject params) {
        logger.warn("回调queryName,参数:" + params);
        UserDetailsDto userDto = new UserDetailsDto();
        userDto.setRealName("未设置");
        return R.success(userDto);
    }

    @Override
    public R<UserDetailsDto> getUserInfoById(JSONObject params) {
        logger.warn("回调getUserInfoById,参数:" + params);
        UserDetailsDto userDto = new UserDetailsDto();
        userDto.setRealName("未设置");
        return R.success(userDto);
    }

    @Override
    public R<List<UserDetailsDto>> queryNameList(JSONObject params) {
        logger.warn("回调queryNameList,参数:" + params);
        UserDetailsDto userDto = new UserDetailsDto();
        userDto.setRealName("未设置");
        int length = params.getJSONArray("ids").size();
        List<UserDetailsDto> list = new ArrayList<>(length);
        for (int i = 0; i < length; i++) {
            list.add(i, userDto);
        }
        return R.success(list);
    }

    @Override
    public R<List<String>> queryTagList(JSONObject params) {
        logger.warn("回调queryTagList,参数:" + params);
        return R.success(ErrorEnum.RPC_ERROR);
    }

    @Override
    public R<Set<Integer>> queryFriendList(JSONObject params) {
        logger.warn("回调queryFriendList,参数:" + params);
        return R.success(ErrorEnum.RPC_ERROR);
    }


}
